package com.example.sens.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.example.sens.entity.Performance;
import com.example.sens.service.PerformanceService;
import com.example.sens.utils.Response;
import com.example.sens.vo.ConclusionVo;
import com.example.sens.vo.PerformanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/performance")
public class PerformanceController {

    @Autowired
    private PerformanceService performanceService;

    /**
     * 获取分页数据
     * @param performanceVo
     * @return
     */
    @PostMapping("/getByPage")
    public Response<Page<Performance>> getByPage(@RequestBody PerformanceVo performanceVo) {
        Page<Performance> quizPage = null;
        try {
            quizPage = performanceService.findAll(new Page(performanceVo.getPageNo(), performanceVo.getPageSize()));
        } catch (Exception e) {
            e.printStackTrace();
            return Response.no();
        }
        return Response.yes(quizPage);
    }

    @PostMapping("/updateScore")
    public Response updateScore(@RequestParam("id") Long id,
                                @RequestParam("score") Integer score) {
        Performance conclusion = new Performance();
        conclusion.setId(id);
        conclusion.setScore(score);
        return performanceService.updateScore(conclusion);
    }
}
